package com.atguigu.gmall.search.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.search.dto.SearchParamDto;
import com.atguigu.gmall.search.entity.Goods;
import com.atguigu.gmall.search.service.GoodsService;
import com.atguigu.gmall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/inner/search")
public class GoodsApiController {

    @Autowired
    private GoodsService goodsService ;

    @PostMapping(value = "/saveGoods")
    public Result saveGoods(@RequestBody Goods goods) {
        goodsService.saveGoods(goods) ;
        return Result.ok() ;
    }

    @DeleteMapping(value = "/deleteById/{skuId}")
    public Result deleteById(@PathVariable(value = "skuId") Long skuId) {
        goodsService.deleteById(skuId) ;
        return Result.ok() ;
    }

    @PostMapping(value = "/search")
    public Result<SearchResponseVo> search(@RequestBody SearchParamDto searchParamDto) {
        SearchResponseVo searchResponseVo = goodsService.search(searchParamDto) ;
        return Result.build(searchResponseVo , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/updateHotScore/{skuId}/{hotScore}")
    public Result updateHotScore(@PathVariable(value = "skuId") Long skuId , @PathVariable(value = "hotScore") Long hotScore) {
        goodsService.updateHotScore(skuId , hotScore) ;
        return Result.ok() ;
    }

}
